<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="bread">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 列表 -->
    <el-table :data="rightsList" style="width: 100%">
      <el-table-column type="index" :index="indexMethod"></el-table-column>
      <el-table-column prop="authName" label="权限名称" width="180"></el-table-column>
      <el-table-column prop="path" label="路径" width="180"></el-table-column>
      <el-table-column label="等级">
        <!-- 通过scope.row可以拿到当前行的等级信息,用v-if判断后进行显示 -->
        <template slot-scope="scope">
          <span v-if="scope.row.level === '0'">一级</span>
          <span v-else-if="scope.row.level === '1'">二级</span>
          <span v-else>三级</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
/*eslint-disable*/
export default {
  data() {
    return {
      rightsList: [
        {
          authName: "",
          path: "",
          level: ""
        }
      ]
    };
  },
  // 一进入页面就要进行渲染
  created() {
    this.loadRightsList();
  },
  methods: {
    // 权限列表渲染
    async loadRightsList() {
      let res = await this.$axios.get("rights/list");
      // console.log(res);
      // 获取成功的话，将获取到的数据赋值给rightsList
      if (res.data.meta.status === 200) {
        this.rightsList = res.data.data;
      }
    },

    // 自定义序列
    indexMethod(index) {
      // index就是从0开始展示的
      return index;
    }
  }
};
</script>

<style scoped lang='less'>
.bread {
  height: 50px;
  line-height: 50px;
  background-color: #d4dae0;
  padding-left: 20px;
}
</style>
